import asyncio
import time

'''demo1'''


async def demo1():
    print("start")
    await asyncio.sleep(1)
    print("end")


# asyncio.run(demo1())

'''demo2'''


async def say_after(delay, what):
    await asyncio.sleep(delay)
    print(what)


async def demo2():
    print(f"started at {time.strftime('%X')}")
    await say_after(1, 'start')
    await say_after(2, 'end')
    print(f"finished at {time.strftime('%X')}")


asyncio.run(demo2())

'''demo3'''


async def demo3():
    task1 = asyncio.create_task(say_after(1, 'start'))
    task2 = asyncio.create_task(say_after(2, 'end'))

    print(f"started at {time.strftime('%X')}")
    await task1
    await task2
    print(f"finished at {time.strftime('%X')}")

asyncio.run(demo3())

